<?php
declare(strict_types=1);

namespace App\Library;

class AppFunction
{
    // 获取本周的所有日期
    public static function getWeekDayData(): array
    {
        $first_day_of_week = strtotime('this week Monday');
        $last_day_of_week = strtotime('this week Sunday');

        $weeks = [];

        for ($i = $first_day_of_week; $i <= $last_day_of_week; $i += 86400) {
            $current_date = date('Y-m-d', $i);
            $weeks[] = $current_date;
        }
        return $weeks;
    }

    /**
     * 获取本周的开始日期和结束日期
     * @return array
     */
    public static function getWeekFirstLastDay(): array
    {
        $first_day_of_week = strtotime('this week Monday');
        $last_day_of_week = strtotime('this week Sunday');
        return [date("Y-m-d H:i:s", $first_day_of_week), date("Y-m-d H:i:s", $last_day_of_week)];
    }

    // 获取星座
    public static function getConstellation(string $birthday): string
    {
        $constellation = '';
        $constellations = array(
            array('20' => '水瓶座'), array('19' => '双鱼座'),
            array('21' => '白羊座'), array('20' => '金牛座'),
            array('21' => '双子座'), array('22' => '巨蟹座'),
            array('23' => '狮子座'), array('23' => '处女座'),
            array('23' => '天秤座'), array('24' => '天蝎座'),
            array('22' => '射手座'), array('22' => '摩羯座')
        );

        try {
            $month = explode("-", $birthday)[1];
            $day = explode("-", $birthday)[2];
            foreach ($constellations as $item) {
                foreach ($item as $key => $value) {
                    if ($month == 1 && $day >= $key || $month == 2 && $day <= 18) {
                        $constellation = $value;
                    } elseif ($month == 2 && $day >= $key || $month == 3 && $day <= 20) {
                        $constellation = $value;
                    } elseif ($month == 3 && $day >= $key || $month == 4 && $day <= 19) {
                        $constellation = $value;
                    } elseif ($month == 4 && $day >= $key || $month == 5 && $day <= 20) {
                        $constellation = $value;
                    } elseif ($month == 5 && $day >= $key || $month == 6 && $day <= 21) {
                        $constellation = $value;
                    } elseif ($month == 6 && $day >= $key || $month == 7 && $day <= 22) {
                        $constellation = $value;
                    } elseif ($month == 7 && $day >= $key || $month == 8 && $day <= 22) {
                        $constellation = $value;
                    } elseif ($month == 8 && $day >= $key || $month == 9 && $day <= 22) {
                        $constellation = $value;
                    } elseif ($month == 9 && $day >= $key || $month == 10 && $day <= 23) {
                        $constellation = $value;
                    } elseif ($month == 10 && $day >= $key || $month == 11 && $day <= 22) {
                        $constellation = $value;
                    } elseif ($month == 11 && $day >= $key || $month == 12 && $day <= 21) {
                        $constellation = $value;
                    } elseif ($month == 12 && $day >= $key || $month == 1 && $day <= 19) {
                        $constellation = $value;
                    }
                }
            }
            return $constellation;
        } catch (\Throwable $throwable) {
            return "星座未知";
        }
    }
}
